
let data = cc.Class({
    extends: cc.Component,

    ctor:function(){
        this.gData ={};
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {

    },

    // update (dt) {},

    // Methods
    save(){
        let str = JSON.stringify(this.gData);
        cc.sys.localStorage.setItem('data',str);
    },
    load(){
        // console.log('load data');
        let str = cc.sys.localStorage.getItem('data');
        this.gData = JSON.parse(str);
        if(this.gData === null){
            this.gData ={};
        }
        return this.gData;
    },
    del(){
        cc.sys.localStorage.removeItem('data');
    },
    AddGold:function(gold){
        if(this.gData.m_Gold===null){
            this.gData.m_Gold = 0;
        }
        this.gData.m_Gold +=gold;
        this.save();
    },
    GetGold:function(){
        if(this.gData.m_Gold==null){
            this.gData.m_Gold =0;
        }
        return this.gData.m_Gold;
    },
    //设置金币获取时间
    setGoldTime(time){
        this.gData.m_GetGoldTime = time;
        this.save();
    },
    getGoldTime(){
        if(this.gData.m_GetGoldTime==null){
            this.gData.m_GetGoldTime =3;
        }
        return this.gData.m_GetGoldTime;
    },
    //设置奖励的金币数目
    setAwardGold(gold){
        this.gData.m_AwardGold = gold;
        this.save();
    },
    getAwardGold(){
        if(this.gData.m_AwardGold === null||this.gData.m_AwardGold===undefined){
            this.gData.m_AwardGold =3;
        }
        return this.gData.m_AwardGold;
    },
    //奖励了多少金币
    AddTaskGold(gold){
        if(this.gData.m_TaskGold === null||this.gData.m_TaskGold===undefined){
            this.gData.m_TaskGold = 0;
        }
        this.gData.m_TaskGold +=gold;
        this.save();
    },
    GetTaskGold(){
        if(this.gData.m_TaskGold === null||this.gData.m_TaskGold===undefined){
            this.gData.m_TaskGold = 0;
        }
        return this.gData.m_TaskGold;
    },
    clearTaskGold(){
        this.gData.m_TaskGold = 0;
        this.save();
        // console.log(' this.gData.m_TaskGold ', this.gData.m_TaskGold );
    },

});
window.gDataCtrl = new data();
// console.log('gDataCtrl',gDataCtrl);
window.gDataCtrl.load();
window.gData = window.gDataCtrl.gData;
